package org.admin.entity.dto;

import core.validate.Rule;
import lombok.Data;
import org.admin.entity.BaseDto;

import java.util.List;
import java.util.Objects;

@Data
public class UserDto extends BaseDto<UserDto> {
    protected UserDto inst(){
        return this;
    }
    public UserDto(){
        addRule(new Rule<?>[] {
                Rule.Number("id").min(0, ""),
                Rule.String("username")
                        .between(5, 16, "用户名称长度错误"),
                Rule.String("password")
                        .between(6, 32, "用户密码长度错误")
                        .regex("^[a-zA-Z0-9-_]+$", "用户密码格式不正确"),
                Rule.String("email")
                        .max(32, "电子邮件地址过长")
                        .regex("^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$", "电子邮件地址格式不正确"),
                        //.email(),
                Rule.String("nickname")
                        .between(2, 16, "用户昵称长度错误"),
                Rule.String("picture")
                        .max(128, "头像图片地址长度过长"),
                Rule.Boolean("gender")
                        .setMessages("请正确选择性别"),
                Rule.Array("roleIds")
                        .min(1, "未选择角色"),
                Rule.Number("roleId").min(1, "指定角色不存在"),
                Rule.Number("current").min(1, "当前分页错误"),
                Rule.Number("size").onPreCheck(val -> Objects.requireNonNullElse(val, 20))
                        .min(1, "分页数量错误"),
                Rule.Array("ids").min(1, "未指定删除项"),

        });

    }


    private Integer id;
    private String email;
    private String username;
    private String password;
    private String nickname;
    private String picture;
    private Boolean gender;
    private List<Integer> roleIds;
    private Integer roleId;
    private Integer current;
    private Integer size;
    private List<Integer> ids;
}
